package com.me.brainlessbirds.actors.map;

import java.util.ArrayList;
import com.me.brainlessbirds.actors.obstacles.Obstacle;
import com.me.brainlessbirds.actors.survivors.Survivor;
import com.me.brainlessbirds.actors.zombies.Zombie;
import com.me.brainlessbirds.screens.GameScreen;

public class GameMap
{
	private ArrayList<Integer>		rows		= new ArrayList<Integer>();
	private ArrayList<SpawnButton>	spawns		= new ArrayList<SpawnButton>();
	private Integer					rowHeight	= 160;

	public GameMap()
	{
		rows.add((int) (GameScreen.HEIGHT / 2) + (int) (GameScreen.HEIGHT / 20));
		rows.add((int) (GameScreen.HEIGHT / 2) - (int) (GameScreen.HEIGHT / 12));
		rows.add((int) (GameScreen.HEIGHT / 2) - (int) (GameScreen.HEIGHT / 4.5));
		initSpawnButtons();
	}

	private void initSpawnButtons()
	{
		for (Integer y : this.rows)
		{
			spawns.add(new SpawnButton(y));
		}
	}

	public ArrayList<Integer> getRows()
	{
		return this.rows;
	}

	public Integer getRow(float y)
	{
		int selectedRow = 0;
		int decal = this.rowHeight;
		for (Integer rowPos : this.rows)
		{
			int cDecal = (int) Math.abs(y - rowPos);
			if (cDecal < decal)
			{
				decal = cDecal;
				selectedRow = rowPos;
			}
		}
		return selectedRow;
	}

	public ArrayList<Zombie> getZombiesFromRow(int row)
	{
		ArrayList<Zombie> zombies = new ArrayList<Zombie>();
		for (Zombie z : GameScreen.get().zombies)
		{
			if (row == this.rows.indexOf((int) (z.getY() + z.getHeight() / 2)))
			{
				zombies.add(z);
			}
		}
		return zombies;
	}

	public ArrayList<Obstacle> getObstaclesFromRow(int row)
	{
		ArrayList<Obstacle> obstacles = new ArrayList<Obstacle>();
		for (Obstacle z : GameScreen.get().obstacles)
		{
			if (row == this.rows.indexOf((int) (z.getY() + z.getHeight() / 2)))
			{
				obstacles.add(z);
			}
		}
		return obstacles;
	}

	public ArrayList<Survivor> getSurvivorsFromRow(int row)
	{
		ArrayList<Survivor> survivors = new ArrayList<Survivor>();
		for (Survivor z : GameScreen.get().survivors)
		{
			if (row == this.rows.indexOf((int) (z.getY() + z.getHeight() / 2)))
			{
				survivors.add(z);
			}
		}
		return survivors;
	}

	public ArrayList<SpawnButton> getSpawnButtons()
	{
		return this.spawns;
	}
}
